﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;

using ProjectBase.Core;

using $prjsn$.Common.Data.Services;
using $prjsn$.Entity.Services;

namespace $safeprojectname$.Services
{
    public class FirmFilterValidator : FilterValidatorBase<ContentType, ContentTypeFilter, int>
    {
        protected override void Init(RuleCollection<ContentTypeFilter> rules) { base.Init(rules); }
    }

    public class ContentTypeValidator : EntityValidatorBase<ContentType, int, IContentTypeDao>
    {
        protected override void Init(RuleCollection<ContentType> rules)
        {
            // string
            rules.For(entity => entity.Description).RequireLengthBetween(0, 250);
            rules.For(entity => entity.Suffix).RequireLengthBetween(1, 10);

            // unique Code
            rules.For(entity => entity.Code).RequireLengthBetween(1, 150)
                .BreakOnError();
            rules.IsUnique(entity => Dao.Find(entity.ID, new ContentTypeFilter() { CodeExact = entity.Code }), "Code");

            // Delete
            // TODO
            // rules.Assure(IsContentTypeInUse).WhenDeleting();
        }

    }
}